﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HotelManager.BusinessLogic.Abstract;
using HotelManager.BusinessLogic.Concrete;
using HotelManager.DataAccess.Abstract;
using HotelManager.DataAccess.Concrete;
using Ninject;

namespace HotelManager.WebUI.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private IKernel ninjectKernel;

        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            return controllerType == null ? null : (IController) ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            // Service binding
            ninjectKernel.Bind<IHotelService>().To<HotelService>();
            ninjectKernel.Bind<ILocationService>().To<LocationService>();

            // Data access binding
            ninjectKernel.Bind<IHotelRepository>().To<HotelRepository>();
            ninjectKernel.Bind<ILocationRepository>().To<LocationRepository>();
        }
    }
}